<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>卡片翻转</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      .wrapper {
        margin: 200px auto;
        width: 200px;
        height: 400px;
        /* 开启三维空间, 默认就把里面的元素给锁定住了。所以不需要加相对定位*/
        transform-style: preserve-3d;
        /* 透视，近大远小 */
        perspective: 1000px;
      }
      .box {
        position: absolute;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        border-radius: 20px;
        box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
        /* 图片翻面时，隐藏 */
        backface-visibility: hidden;
        transition: all 1s;
      }
      .box-1 {
        background-color: orange;
      }
      .box-2 {
        transform: rotateY(180deg);
        background-color: chartreuse;
      }
      .wrapper:hover .box-1 {
        transform: rotateY(-180deg);
      }
      .wrapper:hover .box-2 {
        transform: rotateY(0);
      }
    </style>
  </head>
  <body>
    <div class="wrapper">
      <div class="box box-1">正面</div>
      <div class="box box-2">反面</div>
    </div>
  </body>
</html>
